package com.taldh.algorithm.array;

import org.junit.Assert;
import org.junit.Test;

public class RemoveElementSolution {

    public int removeElement(int[] nums, int val) {
        int len = nums.length;
        int lastNotEqValIndex = 0;
        for (int i = 0; i < len; i++) {
            if (nums[i] != val) {
                nums[lastNotEqValIndex++] = nums[i];
            }
        }

        return lastNotEqValIndex;
    }

    @Test
    public void test() {
        Assert.assertEquals(5, removeElement(new int[]{0,1,2,2,3,0,4,2}, 2));
    }


}